package org.vectrics.recruiter.struts.tag;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.ecs.html.A;
import org.apache.ecs.html.IMG;
import org.apache.log4j.Category;
import org.vectrics.DataException;
import org.vectrics.SystemException;
import org.vectrics.common.html.BorderTable;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Form;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.common.html.TextHelper;
import org.vectrics.common.pagelist.PageList;
import org.vectrics.company.Company;
import org.vectrics.domain.Domain;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.location.Location;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.recruiter.job.JobSearchCriteria;
import org.vectrics.recruiter.job.JobStatusType;
import org.vectrics.recruiter.struts.admin.JobSearchActionHelper;
import org.vectrics.struts.PageListTag;
import org.vectrics.user.Person;

/**
 * @author mmoore
 * 
 *         Shows a list of job postings. This list can take different forms and
 *         can include different categories of jobs. If 'observer' property is
 *         'true', the job list will contain just jobs that are of concern to
 *         the current authentication user.
 */
public class JobListTag extends PageListTag {
    public static final long serialVersionUID = 199324534325L;

    static private Category log = Category.getInstance(JobListTag.class);

    static private SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");

    static public String USER_PARAM = "user";

    static public String PAGE_DESCRIPTION = null;

    public static String TABLE_FONT = "subFont";

    public static String TABLE_FONT_GREEN = "subFontGreen";

    public static String TABLE_FONT_RED = "subFontRed";

    private String permissionJobView;

    private String observer = "false";

    private String activeOnly = "false";

    private String usePageList = "true";

    private String candidateId = null;

    private String myJobs = "false";

    private JobDetailDisplayOptions displayOptions = null;

    public JobListTag() {
        super();
    }

    @Override
    protected PageList createPageList() {
        log.debug("createPageList() called");
        JobSearchActionHelper helper = new JobSearchActionHelper();
        displayOptions = helper.loadDisplayOptions(getRequest());
        if (displayOptions == null)
            throw new SystemException("Job display options not attached to session before rendering JobListTag.");

        JobSearchCriteria criteria = getCriteria();

        JobPageList pageList = new JobPageList(criteria);
        return pageList;
    }

    protected boolean showActiveCriteria() {
        return true;
    }

    private void addTopOfPageField(final Table table, final String label, final String value) {
        Row fieldRow = table.addRow();
        Cell labelCell = fieldRow.addCell();
        Cell sepCell = fieldRow.addCell();
        Cell valueCell = fieldRow.addCell();
        labelCell.addElement(TextHelper.getFont("subFont", label + ":"));
        sepCell.addElement(TextHelper.getFont("subFont", "&nbsp;"));
        valueCell.addElement(TextHelper.getFont("subFont", value));
    }

    @Override
    protected String getTopOfPageContent() {
        Table table = new Table();
        table.setWidth("100%");
        Row outerRow = table.addRow();
        Cell outerCell = outerRow.addCell();
        outerCell.setAlign("right");

        log.debug("entering: getTopOfPageContent()");
        Table innerTable = new BorderTable();
        innerTable.setWidth("50%");
        outerCell.addElement(innerTable);
        Row row = innerTable.addRow();
        Cell contentCell = row.addCell();
        contentCell
                .addElement(TextHelper.getFont("subFont", "<b>" + getPhrase("heading.job.search.criteria") + "</b>"));

        Table fieldsTable = new Table();
        fieldsTable.setWidth("100%");
        contentCell.addElement(fieldsTable);
        JobSearchCriteria criteria = getJobCriteria();

        int allDomainsCount = CoreServiceLocator.getSystemService().findAllDomains().size();

        if (criteria.getDomains().size() > 0) {
            if (criteria.getDomains().size() < allDomainsCount) {
                String domainList = "";
                Iterator iter = criteria.getDomains().iterator();
                while (iter.hasNext()) {
                    Domain domain = (Domain) iter.next();
                    log.debug("getTopOfPageContent() - company id specified," + " finding header for company: "
                            + domain.getId());
                    domainList += TextHelper.getFont("subFont", domain.getDescription());
                    if (iter.hasNext()) {
                        domainList += TextHelper.getFont("subFont", ",&nbsp;");
                    }
                }
                addTopOfPageField(fieldsTable, getPhrase("prompt.job.search.domains"), domainList);
            } else {
                addTopOfPageField(fieldsTable, getPhrase("prompt.job.search.domains"),
                        getPhrase("phrase.all.companies"));
            }
        } else {
            log.debug("Data owners not specified in criteria");
        }

        if (showActiveCriteria()) {
            String statusTypes = "";
            if (criteria.getStatusTypes().size() > 0) {
                Iterator iter = criteria.getStatusTypes().iterator();
                while (iter.hasNext()) {
                    String statusTypeCode = (String) iter.next();
                    statusTypes += statusTypeCode;
                    if (iter.hasNext()) {
                        statusTypes += ", ";
                    }
                }
            } else {
                // this.addTopOfPageField(fieldsTable,
                // this.getPhrase("prompt.job.status"),
                // this.getPhrase("phrase.job.status.all"));
            }
        }

        if (criteria.getSearchWords() != null && criteria.getSearchWords().size() > 0) {
            String searchWords = "";
            Iterator iter = criteria.getSearchWords().iterator();
            while (iter.hasNext()) {
                String word = (String) iter.next();
                searchWords += word;
                if (iter.hasNext()) {
                    searchWords += " ";
                }
            }
            addTopOfPageField(fieldsTable, getPhrase("phrase.job.search.words"), searchWords);
        }

        if (criteria.getEarliestPostDate() != null) {
            addTopOfPageField(fieldsTable, getPhrase("phrase.date.earliest"),
                    dateFormatter.format(criteria.getEarliestPostDate()));
        }
        if (criteria.getLatestPostDate() != null) {
            addTopOfPageField(fieldsTable, getPhrase("phrase.date.latest"),
                    dateFormatter.format(criteria.getLatestPostDate()));
        }

        if (criteria.getLocations() != null && criteria.getLocations().size() > 0) {
            String locations = "";
            Iterator iter = criteria.getLocations().iterator();
            while (iter.hasNext()) {
                Location location = (Location) iter.next();
                locations += location.getName();
                if (iter.hasNext()) {
                    locations += ", ";
                }
            }
            addTopOfPageField(fieldsTable, getPhrase("phrase.job.location"), locations);
        }

        if (criteria.getJobFunctions() != null && criteria.getJobFunctions().size() > 0) {
            String jobFunctions = "";
            Iterator iter = criteria.getJobFunctions().iterator();
            while (iter.hasNext()) {
                JobFunction function = (JobFunction) iter.next();
                if (function != null) {
                    jobFunctions += function.getDescription();
                    if (iter.hasNext()) {
                        jobFunctions += ", ";
                    }
                }
            }
            addTopOfPageField(fieldsTable, getPhrase("prompt.job.function"), jobFunctions);
        }

        if (criteria.getCandidateId() != null) {
            Person user = CoreServiceLocator.getPersonService().findPersonById(criteria.getCandidateId());
            if (user == null) {
                addTopOfPageField(fieldsTable, getPhrase("prompt.candidate.name"), user.getName());
            }
        }
        return table.toString();
    }

    protected boolean userCanRemove(final Person authPerson, final Job job) {
        return true;
    }

    @Override
    protected boolean usePageListing() {
        boolean result = true;
        if (usePageList.toLowerCase().equals("false")) {
            result = false;
        }
        return result;
    }

    @Override
    protected String getNoElementsMessage() {
        return getPhrase("phrase.jobs.none.found");
    }

    private String getCompanyPathName(final Company company) {
        String name = company.getName();
        if (company.getParent() != null) {
            name = getCompanyPathName(company.getParent()) + " / " + name;
        }
        return name;
    }

    @Override
    protected String getDescription() {
        return PAGE_DESCRIPTION;
    }

    protected JobSearchCriteria getJobCriteria() {
        JobSearchCriteria criteria = (JobSearchCriteria) getPageList().getCriteria();
        return criteria;
    }

    @Override
    protected String getPageListLink() {
        return getContextPath() + "/admin/jobs/samecriteria.do";
    }

    private void renderListAsBlocks(final String str, final Cell listCell, final Collection jobs) {

        Table jobListTable = new BorderTable();
        listCell.addElement(jobListTable);

        log.debug("Make a header row");
        Row hdrRow = jobListTable.addRow();
        hdrRow.setDefaultBgImage(getContextPath() + "/site-graphics/tbl_hdr.gif");

        Cell contentHdrCell = hdrRow.addCell();
        // contentHdrCell.setClass("tableHdrBg");
        contentHdrCell.addElement(TextHelper.getFont("tableHdrFont", "Job Information"));

        Cell actionHdrCell = hdrRow.addCell();
        // actionHdrCell.setClass("tableHdrBg");
        actionHdrCell.addElement(TextHelper.getFont("tableHdrFont", "Actions"));

        log.debug("Display the detail rows");
        Iterator iter = jobs.iterator();
        while (iter.hasNext()) {
            Job job = (Job) iter.next();
            String cellClass = "formBg1";
            addBlockRow(jobListTable, job, cellClass);
        }
    }

    private void addBlockRow(final Table listTable, final Job job, final String cellClass) {
        Row row = listTable.addRow();
        Cell contentCell = row.addCell();
        contentCell.setClass(cellClass);
        addBlockContent(contentCell, job);

        Cell actionCell = row.addCell();
        actionCell.setClass(cellClass);
        addBlockLinks(actionCell, job);
    }

    private void addBlockContent(final Cell mainCell, final Job job) {
        Table table = new Table();
        table.setWidth("100%");
        table.setCellSpacing(3);
        table.setCellPadding(2);
        mainCell.addElement(table);

        makeBlockTitleRow(table, job);

        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.setColSpan(2);
        // cell.setClass("formBg1");
        cell.addElement(TextHelper.getFont("subFont", job.getDescription()));

        makeBlockLocationRow(table, job);

        if (displayOptions.getShowReferenceCode()) {
            makeRefCodeRow(table, job);
        }

        row = table.addRow();
        cell = row.addCell();
        cell.setColSpan(2);
        // cell.setClass("formBg1_1");
        if (job.getHiringManager() == null) {
            cell.addElement(TextHelper.getFont("subFont", "Hiring Manager: " + "Not Specified"));
        } else {
            cell.addElement(TextHelper.getFont("subFont", "Hiring Manager: " + job.getHiringManager()));
        }

        if (displayOptions.getShowRecruiter()) {
            makeBlockRecruitRow(table, job);
        }
    }

    private void makeBlockTitleRow(final Table table, final Job job) {
        Row row = table.addRow();
        Cell cell = row.addCell();
        // cell.setClass("formBg1_1");
        cell.setWidth("90%");
        cell.addElement(TextHelper.getFont("subFont", "<b>" + job.getTitle() + "</b>"));

        cell = row.addCell();
        cell.setVAlign("top");
        // cell.setClass("formBg1_1");
        IMG icon = new IMG();
        String text = "";
        if (job.getCurrentStatus().getStatusType().getCode().equals(JobStatusType.STATUS_POSTED)) {
            icon.setSrc("/hrs-intranet/graphics/active.gif");
            icon.setAlt(getPhrase("phrase.active"));
            text = TextHelper.getFont("subFontGreen",
                    "<b>" + job.getCurrentStatus().getStatusType().getDescription(getLocale()) + "</b>").toString();

        } else {
            icon.setSrc("/hrs-intranet/graphics/inactive.gif");
            icon.setAlt(getPhrase("phrase.inactive"));
            text = TextHelper.getFont("subFontRed",
                    "<b>" + job.getCurrentStatus().getStatusType().getDescription(getLocale()) + "</b>").toString();
        }

        Table statusTable = new Table();
        cell.addElement(statusTable);
        Row statusRow = statusTable.addRow();
        Cell statusCell = statusRow.addCell();
        statusCell.addElement(icon);
        statusCell = statusRow.addCell();
        statusCell.addElement(text);
    }

    private void makeRefCodeRow(final Table table, final Job job) {
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.setColSpan(2);
        // cell.setClass("formBg1_1");
        if (job.getReferenceId() == null) {
            cell.addElement(TextHelper.getFont("subFont",
                    getPhrase("prompt.job.reference.id") + ": " + job.getReferenceId()));
        } else {
            cell.addElement(TextHelper
                    .getFont("subFont", getPhrase("prompt.job.reference.id") + ": " + "Not Specified"));
        }
    }

    private void makeBlockLocationRow(final Table table, final Job job) {
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.setColSpan(2);
        // cell.setClass("formBg1_1");
        cell.addElement(TextHelper.getFont("subFont",
                getPhrase("prompt.job.location") + ": " + job.getLocationDescription()));
    }

    private void makeBlockRecruitRow(final Table table, final Job job) {
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.setColSpan(2);
        // cell.setClass("formBg1_1");
        cell.addElement(TextHelper.getFont("subFont", getPhrase("prompt.job.primary.recruiter") + ": "
                + getRecruiterDescription(job)));
    }

    private String getRecruiterDescription(final Job job) {
        String description = "";
        Person recruiter = job.getPrimaryRecruiter();
        if (recruiter == null) {
            description = "Not Specified";
        } else {
            description = recruiter.getName();
        }
        return description;
    }

    protected String getViewJobHref(final Job job) {
        String href = getContextPath() + "/admin/jobs/view.do" + "?jobId=" + job.getId();
        return href;
    }

    protected String getJobPdfHref(final Job job) {
        Date now = new Date();
        String href = getContextPath() + "/report/admin/job.pdf" + "?report=job&jobId=" + job.getId() + "&time="
                + now.getTime()
        // + "&domainId=" + ThreadProperties.getDomain().getId()
        // + "&userName=" + ThreadProperties.getPerson().getUser().getUserName()
        // + "&password=" + ThreadProperties.getPerson().getUser().getPassword()
        ;
        return href;
    }

    private void addBlockLinks(final Cell mainCell, final Job job) {
        Table linkTable = new Table();
        linkTable.setWidth("100%");
        mainCell.addElement(linkTable);

        Row linkRow = linkTable.addRow();
        Cell cell = linkRow.addCell();
        A editLink = new A();
        editLink.setClass("lnkSubHover");
        String viewHref = getViewJobHref(job);
        editLink.setHref(getViewJobHref(job));
        editLink.addElement(getPhrase("phrase.view"));
        editLink.setHref(viewHref);
        editLink.setID("view_" + job.getId());
        cell.addElement(editLink);

        if (getJobPdfHref(job) != null) {
            linkRow = linkTable.addRow();
            cell = linkRow.addCell();
            A pdfLink = new A();
            pdfLink.setClass("lnkSubHover");
            pdfLink.setHref(getJobPdfHref(job));
            pdfLink.addElement("PDF");
            cell.addElement(pdfLink);
        }
    }

    private void renderListAsRows(final String str, final Cell listCell, final Collection jobs) {

        if (log.isDebugEnabled()) {
            log.debug("renderListAsRows() called");
            log.debug("renderListAsRows() jobIds.size = " + jobs.size());
        }

        Person user = null;
        try {
            user = getAuthPerson();
            if (jobs.size() > 0) {
                Iterator iter = jobs.iterator();
                BorderTable listTable = new BorderTable();
                listTable.setWidth("100%");
                listCell.addElement(listTable);
                Row hdrRow = listTable.addRow();
                hdrRow.setDefaultBgImage(getContextPath() + "/site-graphics/tbl_hdr.gif");

                Cell hdrCell = null;

                // columna Date Posted
                hdrCell = hdrRow.addCell();
                hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.date.posted")));
                hdrCell.setWidth(69);

                /*
                 * if (displayOptions.getShowActiveIndicator()) { hdrCell =
                 * hdrRow.addCell(); hdrCell.setWidth(0);
                 * hdrCell.addElement(TextHelper.getFont("tableHdrFont",
                 * "&nbsp;")); }
                 */

                if (displayOptions.getShowReferenceCode()) {
                    hdrCell = hdrRow.addCell();
                    hdrCell.setWidth(80);
                    hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.reference.id")));
                }

                /*
                 * if (displayOptions.getShowApprovalGroups()) { hdrCell =
                 * hdrRow.addCell();
                 * hdrCell.addElement(TextHelper.getFont("tableHdrFont",
                 * this.getPhrase("prompt.job.approval.groups"))); }
                 */

                hdrCell = hdrRow.addCell();
                hdrCell.setWidth(80);
                hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.title")));
                // hdrCell.setWidth(220);

                /*
                 * if (this.displayCompany()) { hdrCell = hdrRow.addCell();
                 * hdrCell.addElement(TextHelper.getFont("tableHdrFont",
                 * this.getPhrase("prompt.job.company"))); }
                 * 
                 * if (displayOptions.getShowCompanyCode()) { hdrCell =
                 * hdrRow.addCell();
                 * hdrCell.addElement(TextHelper.getFont("tableHdrFont",
                 * this.getPhrase("prompt.job.company.code"))); }
                 */

                // columna de Primery Recruiter
                hdrCell = hdrRow.addCell();
                hdrCell.setWidth(115);
                hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.primary.recruiter")));

                // columna de Request By
                hdrCell = hdrRow.addCell();
                hdrCell.setWidth(117);
                hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.requester")));

                if (displayOptions.getShowLocation()) {
                    hdrCell = hdrRow.addCell();
                    hdrCell.setWidth(150);
                    hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.location")));
                }

                // columna Status
                if (getShowStatus()) {
                    hdrCell = hdrRow.addCell();
                    hdrCell.setWidth(75);
                    hdrCell.addElement(TextHelper.getFont("tableHdrFont", getPhrase("prompt.job.status")));
                }

                /**
                 * Verifica que el usuario tenga permiso antes de dibujar las
                 * columnas 'Option' y 'Export'.
                 */
                setPermission(getPermissionJobView());
                if (this.hasPermission()) {
                    if (displayOptions.getShowPdfLink()) {
                        hdrCell = hdrRow.addCell();
                        hdrCell.addElement(TextHelper.getFont("tableHdrFont", "Options"));
                    }
                    hdrCell = hdrRow.addCell();
                    hdrCell.addElement(TextHelper.getFont("tableHdrFont", "PDF"));
                }

                while (iter.hasNext()) {
                    Job job = (Job) iter.next();
                    addJobRow(job, listTable, user);
                }
            }
        } catch (Exception ex) {
            log.error("Exception in showList()", ex);
            throw new DataException("Exception in showList()", ex);
        }
    }

    @Override
    protected void showList(final String str, final Cell listCell, final List jobs, final Form form) {

        if (displayOptions.getRowStyle() == JobDetailDisplayOptions.STYLE_BLOCK) {
            renderListAsBlocks(str, listCell, jobs);
        } else {
            renderListAsRows(str, listCell, jobs);
        }

    }

    /*
     * 
     * private boolean jobOkToDisplay(Job job, User authUser) throws
     * DataException {log.debug(
     * "jobOkToDisplay() - method to determine whether the passed job should be displayed"
     * ); boolean result = false;
     * 
     * if (this.getObserver().toLowerCase().equals("true") == false) {
     * log.debug("jobOkToDisplay() - observer is false, job will display");
     * result = true; } else { if (jobManager.isJobObserver(job, authUser)) {
     * log.debug(
     * "jobOkToDisplay() - observer is true and current user is an observer of the job, job will display"
     * ); result = true; } else {log.debug(
     * "jobOkToDisplay() - observer is true and current user is NOT an observer of the job, job will  NOT display"
     * ); } }
     * 
     * if (job.getActive() == false) { if
     * (this.getActiveOnly().toLowerCase().equals("true")) { result = false; } }
     * return(result); }
     */

    public JobSearchCriteria getCriteria() {
        JobSearchActionHelper helper = new JobSearchActionHelper();
        JobSearchCriteria criteria = helper.loadCriteria(getRequest());

        if (criteria == null) {
            criteria = new JobSearchCriteria();
        }

        // if (getAdmin().equals("true")) {
        // Set domains =
        // CoreServiceLocator.getPersonService().findDomainsWithUserPrivilege
        // (getAuthPerson(),
        // "job.view");
        // criteria.setDomains(domains);
        // } else {
        Set domains = new HashSet();
        domains.add(ThreadProperties.getDomain());
        criteria.setDomains(domains);
        // }

        if (getMyJobs().trim().toLowerCase().equals("true")) {
            criteria.setPerson(ThreadProperties.getPerson());
        }
        return criteria;
    }

    protected boolean displayCompany() {
        JobSearchCriteria criteria = getCriteria();
        return displayOptions.getShowCompany();

    }

    protected boolean getShowStatus() {
        boolean result = displayOptions.getShowStatus();
        return result;
    }

    void addJobRow(final Job job, final Table listTable, final Person authUser) {
        log.debug("addJobRow() - method to display passed job");
        Row row = listTable.addRow();
        Cell cell = null;

        // columna Date Posted
        cell = row.addCell();
        String dateStr = "&nbsp;";
        if (job.getDatePosted() != null) {
            dateStr = dateFormatter.format(job.getDatePosted());
        }

        cell.addElement(TextHelper.getFont(TABLE_FONT, dateStr));

        /*
         * if (displayOptions.getShowActiveIndicator()) { cell = row.addCell();
         * cell.setVAlign("top"); IMG icon = new IMG(); String text = ""; if
         * (job.getActive()) { icon.setSrc("/hrs-intranet/graphics/active.gif");
         * icon.setAlt("Inactive"); text = TextHelper.getFont(TABLE_FONT_GREEN,
         * "&nbsp;Active").toString();
         * 
         * } else { icon.setSrc("/hrs-intranet/graphics/inactive.gif");
         * icon.setAlt("Inactive"); text = TextHelper.getFont(TABLE_FONT_RED,
         * "&nbsp;Inactive").toString(); } if (job.getFeatured()) text +=
         * TextHelper.getFont(TABLE_FONT, "<br>Featured");
         * 
         * cell.addElement(icon);
         * 
         * //cell = row.addCell(); //cell.setVAlign("top");
         * //cell.addElement(text); }
         */

        // columna Reference Id
        if (displayOptions.getShowReferenceCode()) {
            cell = row.addCell();
            if (job.getReferenceId() != null) {
                cell.addElement(TextHelper.getFont(TABLE_FONT, job.getReferenceId()));
            } else {
                cell.addElement(TextHelper.getFont(TABLE_FONT, "&nbsp;"));
            }
        }

        /*
         * if (displayOptions.getShowApprovalGroups()) { cell = row.addCell();
         * JobStatusType currentStatusType =
         * job.getCurrentStatus().getStatusType(); JobStatusTypeApprovalSet
         * approvalSet =
         * RecruitServiceLocator.getJobProvider().findJobStatusApprovals
         * (job.getDomain()); Collection approvals =
         * approvalSet.getApprovalsForJobStatusType(currentStatusType); Set
         * groupDescriptions = new HashSet(); if ((approvals != null) &&
         * (approvals.size() > 0)) { Iterator iter = approvals.iterator(); while
         * (iter.hasNext()) { JobStatusTypeApproval approval =
         * (JobStatusTypeApproval)iter.next(); CompanyPersonGroupType groupType
         * = approval.getCompanyPersonGroupType();
         * groupDescriptions.add(this.getPhrase
         * (groupType.getDescriptionCode())); } } Iterator iter =
         * groupDescriptions.iterator(); while (iter.hasNext()) { String
         * groupName = (String)iter.next();
         * cell.addElement(TextHelper.getFont(TABLE_FONT, groupName)); if
         * (iter.hasNext()) cell.addElement("<br>"); } }
         */

        // columna Job Tittle
        cell = row.addCell();
        cell.addElement(TextHelper.getFont(TABLE_FONT, job.getTitle()));

        JobSearchCriteria criteria = getCriteria();
        if (criteria == null)
            throw new SystemException("Criteria is null");

        /*
         * if (this.displayCompany()) { cell = row.addCell(); String companyName
         * = "&nbsp;"; if (job.getCompany() != null) { Company company =
         * job.getCompany(); if (company != null) companyName =
         * this.getCompanyPathName(company); }
         * cell.addElement(TextHelper.getFont(TABLE_FONT, companyName)); }
         * 
         * 
         * if (displayOptions.getShowCompanyCode()) { cell = row.addCell();
         * String companyCode = "&nbsp;"; if (job.getCompany() != null) {
         * Company company = job.getCompany(); if (company != null) companyCode
         * = company.getReferenceId(); if (companyCode == null) companyCode =
         * company.getName(); } cell.addElement(TextHelper.getFont(TABLE_FONT,
         * companyCode)); }
         */

        // columna de Primery Recruiter
        cell = row.addCell();
        if (job.getPrimaryRecruiter() != null) {
            cell.addElement(TextHelper.getFont(TABLE_FONT, job.getPrimaryRecruiter().getFullName()));
        } else {
            cell.addElement(TextHelper.getFont(TABLE_FONT, "&nbsp;"));
        }

        // columna de Request By
        cell = row.addCell();
        if (job.getRequester() != null) {
            cell.addElement(TextHelper.getFont(TABLE_FONT, job.getRequester().getFullName()));
        } else {
            cell.addElement(TextHelper.getFont(TABLE_FONT, "&nbsp;"));
        }

        // columna Location
        if (displayOptions.getShowLocation()) {
            cell = row.addCell();
            cell.addElement(TextHelper.getFont(TABLE_FONT, job.getLocationDescription()));

        }

        // columna Status
        if (getShowStatus()) {
            cell = row.addCell();
            String statusDescription = getPhrase(job.getCurrentStatus().getStatusType().getDescriptionCode());
            cell.addElement(TextHelper.getFont(TABLE_FONT, statusDescription));
        }

        setPermission(getPermissionJobView());
        if (this.hasPermission()) {
            // TAG1

            /** View Details. */
            cell = row.addCell();
            A editLink = new A();
            editLink.setClass("lnkSubHover");
            editLink.setStyle("color:#A7D34B; font-weight:normal; text-decoration:none; font-family:arial,tahoma,verdana,sans-serif; font-size:11px; font-size-adjust:none; font-style:normal; font-variant:normal;");
            editLink.setHref(getViewJobHref(job));
            editLink.setID("view_job_" + job.getId());
            editLink.addElement(getPhrase("phrase.view"));
            cell.addElement(editLink);

            /** Export to PDF. */
            if (displayOptions.getShowPdfLink()) {
                String pdfHref = getJobPdfHref(job);
                cell = row.addCell();
                A pdfLink = new A();
                pdfLink.setClass("lnkSubHover");
                pdfLink.setStyle("color:#A7D34B; font-weight:normal; text-decoration:none; font-family:arial,tahoma,verdana,sans-serif; font-size:11px; font-size-adjust:none; font-style:normal; font-variant:normal;");
                pdfLink.setTarget("_blank");
                pdfLink.setHref(pdfHref);
                pdfLink.addElement("Export");
                cell.addElement(pdfLink);
            }
        }
        /*
         * if (this.userCanRemove(authUser)) { A removeLink = new A();
         * removeLink.setClass("lnkSubHover");
         * removeLink.setHref(this.getContextPath() + "/admin/jobs/remove.do" +
         * "?id=" + job.getId() + "&page=" + this.getCurrentPage());
         * removeLink.addElement("Remove"); cell = row.addCell();
         * cell.addElement(removeLink); }
         * 
         * A activeLink = new A(); activeLink.setClass("lnkSubHover"); if
         * (job.getActive()) { activeLink.setHref(this.getContextPath() +
         * "/admin/jobs/activate.do" + "?" + JobActivateAction.JOB_PARAM + "=" +
         * job.getId() + "&" + JobActivateAction.ACTIVATE_PARAM + "=false" +
         * "&page=" + this.getCurrentPage());
         * activeLink.addElement("Deactivate"); } else {
         * activeLink.setHref(this.getContextPath() + "/admin/jobs/activate.do"
         * + "?" + JobActivateAction.JOB_PARAM + "=" + job.getId() + "&" +
         * JobActivateAction.ACTIVATE_PARAM + "=true" + "&page=" +
         * this.getCurrentPage()); activeLink.addElement("Activate"); } cell =
         * row.addCell(); cell.addElement(activeLink);
         */
    }

    public String getObserver() {
        return observer;
    }

    public void setObserver(final String observer) {
        this.observer = observer;
    }

    /**
     * @return
     */
    public String getActiveOnly() {
        return activeOnly;
    }

    /**
     * @param activeOnly
     */
    public void setActiveOnly(final String activeOnly) {
        this.activeOnly = activeOnly;
    }

    /**
     * @return
     */
    public String getUsePageList() {
        return usePageList;
    }

    /**
     * @param usePageList
     */
    public void setUsePageList(final String usePageList) {
        this.usePageList = usePageList;
    }

    /**
     * @return Returns the candidateId.
     */
    public String getCandidateId() {
        return candidateId;
    }

    /**
     * @param candidateId
     *            The candidateId to set.
     */
    public void setCandidateId(final String candidateId) {
        this.candidateId = candidateId;
    }

    /**
     * @return Returns the myJobs.
     */
    public String getMyJobs() {
        return myJobs;
    }

    /**
     * @param myJobs
     *            The myJobs to set.
     */
    public void setMyJobs(final String myJobs) {
        this.myJobs = myJobs;
    }

    public void setPermissionJobView(final String permissionJobView) {
        this.permissionJobView = permissionJobView;
    }

    public String getPermissionJobView() {
        return permissionJobView;
    }

}
